package com.example.zhou.filehelper;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.media.MediaMetadataRetriever;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;

/**
 * Created by 11065 on 2016/11/11.
 */

public class AlbumUtil {

    public static byte[] getMusicAlbum(File file) {
        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        mediaMetadataRetriever.setDataSource(file.getAbsolutePath());
        byte[] artBytes = mediaMetadataRetriever.getEmbeddedPicture();
        if (artBytes != null) {
            /*InputStream is = new ByteArrayInputStream(mediaMetadataRetriever.getEmbeddedPicture());
            Bitmap bm = BitmapFactory.decodeStream(is);
            return bm;*/
            return artBytes;
        } else
            return null;
    }


    public static Bitmap getDefaultBitmap(Bitmap bitmap) {
        Bitmap defalut = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(defalut);
        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        return bitmap;
    }


}
